1. /* sdmstdbl.cpp by K.Tsuru */
  2. // function ID = 303 DRADIX
  3. /******************************************************************
  4. SDouble class
  5. It sets a value by double, including long, etc.
  6. [caution]
  7. The usage such as
  8. SDouble x(SNumber::BIN_DEC, 0);
  9. x = 1.0;
  10. must be considered.See Dpow() for example.
  11. A statement
  12. x = 1.1; ... recurring decimal in the binary radix
  13. yields an error. It does not call the function of radix conversion.
  14. ********************************************************************/
  15. #ifndef SN_H
  16. #include "sn.h"
  17. #endif
  18. static const char* const func = "SetDouble";
  19. void SDouble::SetDouble(double d){
  20. if(d == 0.0){
  21. if(RawSign()) SetZero();
  22. return; // d = 0, sign = 0
  23. }
  24. double absd = fabs(d), dp;
  25. fType ip;
  26. uint sz;
  27. if(Type() == BIN_DEC){
  28. rdxExp = 0;
  29. int f = doubleToBinDec(absd, figure, &sz);
  30. if(f < 0) SetError(OVERFLOW_ERR, func, 303);
  31. /*
  32. See above. When the number of figures is three over(45 bits), the probabirity
  33. of recurring decimal is strong.
  34. */
  35. else if(f >= 3) SetError(SYNTAX_ERR, func, 303);
  36. aTail = 0;
  37. sz = min(sz, SNMaxSize(BIN_DEC));
  38. while( (figure(aTail)== 0) && (aTail < sz) ) aTail++;
  39. //"d" is very small and practically equal to zero within the effective figures.
  40. if(aTail == sz){
  41. SetZero(); return;
  42. }
  43. aHead = sz-1u; while(figure(aHead)== 0) aHead--;
  44. goto Ret;
  45. }
  46. if(absd < (double)Radix()){ // abc.0
  47. ip = (fType)(absd + DBL_EPSILON);
  48. dp = fabs(absd - (double)ip);
  49. if(ip && dp < DBL_EPSILON){ //integral part!=0, decimal part==0
  50. if(RawSign()) SetZero();//including memory allocation
  51. aHead = aTail = 1;
  52. figure[1] = ip; rdxExp = 1;
  53. goto Ret;
  54. }
  55. }
  56. rdxExp = doubleToArray(absd, figure, &sz);
  57. #ifndef NDEBUG
  58. assert(figure(1)); // x != 0
  59. #endif
  60. aHead = sz-1; aTail = 1u;
  61. Ret:
  62. SetSign(d);
  63. Reform(303);
  64. }

sdmstdbl.cpp : last modifiled at 2017/04/10 20:34:42(1,878 bytes)
created at 2017/10/07 10:21:14
The creation time of this html file is 2017/10/07 10:30:03 (Sat Oct 07 10:30:03 2017).